package org.zju.moviemotion;

import org.zju.moviemotion.colorpicker.ColorPicker;
import org.zju.moviemotion.colorpicker.ColorPicker.OnColorChangedListener;
import org.zju.moviemotion.colorpicker.OpacityBar;
import org.zju.moviemotion.colorpicker.SVBar;
import org.zju.moviemotion.colorpicker.SaturationBar;
import org.zju.moviemotion.colorpicker.ValueBar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class ColorPickerActivity extends Activity implements OnClickListener,
		OnColorChangedListener {

	private ImageButton forward;
	private ImageButton back;
	ColorPicker picker;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.colorpicker);
		forward = (ImageButton) findViewById(R.id.forward);
		forward.setOnClickListener(this);
		back = (ImageButton) findViewById(R.id.back);
		back.setOnClickListener(this);

		picker = (ColorPicker) findViewById(R.id.picker);
		//SVBar svBar = (SVBar) findViewById(R.id.svbar);
		OpacityBar opacityBar = (OpacityBar) findViewById(R.id.opacitybar);
		SaturationBar saturationBar = (SaturationBar) findViewById(R.id.saturationbar);
		ValueBar valueBar = (ValueBar) findViewById(R.id.valuebar);

		//picker.addSVBar(svBar);
		picker.addOpacityBar(opacityBar);
		picker.addSaturationBar(saturationBar);
		picker.addValueBar(valueBar);

		// To get the color
		// picker.getColor();

		// To set the old selected color u can do it like this
		picker.setOldCenterColor(picker.getColor());
		// adds listener to the colorpicker which is implemented
		// in the activity
		picker.setOnColorChangedListener(this);

		// to turn of showing the old color
		// picker.setShowOldCenterColor(false);

		// adding onChangeListeners to bars
		// opacityBar.setOnOpacityChangeListener(new OnOpacityChangeListener());
		// ValueBar.setOnValueChangeListener(new OnValueChangeListener());
		// saturationBar.setOnSaturationChangeListener(new
		// OnSaturationChangeListener());
	}

	@Override
	public void onClick(View v) {
		if (v == forward) {
			MovieAplication.getInstance().setColor(picker.getColor());
			startActivity(new Intent(getBaseContext(), ResultActivity.class));
		} else if (v == back) {
			finish();
		}
	}

	@Override
	public void onColorChanged(int color) {
		MovieAplication.getInstance().setColor(picker.getColor());
	}
}
